<?php $this->placeholder('display-commercial1')->set(1)?>
<?php 
	$container_class = 'serp';

?>
<?php $this->placeholder('container-class')->set($container_class)?>
<?php //$this->placeholder('container-class')->set('business_directory')?>
<?php $this->headLink()->appendStylesheet(Ac_Util::getImageBaseUrl('/css/custom_serp.v-'.AC_VERSION.'.css'))?>
<?php $this->JQuery()->javascriptCaptureStart()?>
<?php $this->JQuery()->javascriptCaptureEnd()?>

<?php $this->placeholder('big-section-class')->set('');?>
<?php
$get = $_GET;
if (!empty($this->category) && $req['module'] !== 'search') {
    $url = '';
    foreach($get as $k => $v) {
        if (is_array($v)) {
            foreach($v as $k2 => $v2) {
                $url .= $k.'['.$k2.']'.'='.$v2.'&';
            }
        } else {
            $url .= $k.'='.$v.'&';
        }
    }
    $url = $this->category->url().'?'. $url;
} else {
    $url = $this->geturl('regular', 'search', null, array(), $get);
}
$separator = (strpos($url, '?') !== false) ? '&' : '?'; ?>

<article class="article">
    <section class="main_section">
        <section class="refine box">
            <?php if($this->listing_number == 0):?>
                <div>
                    很抱歉，没有找到相关的结果<br>
                    建议您:<br>
                        1. 看看输入的文字是否有误<br>
                        2. 去掉可能不必要的字词，如“的”、“什么”等<br>
                        3. 调整关键字
                </div>
                <?php return;?>
            <?php else:?>
                <?php   $this->partial()->setObjectKey('model');
                    echo $this->partial('index/customization/facet-box.phtml', array(
                        'facet_counts'  => $this->facet_counts,
                        'url'           => $url,
                        'separator'     => $separator,
                        'get'           => $_GET,
                        'disable_price' => $this->disable_price,
                    ));
                ?>
            <?php endif;?>
        </section>
        <section class="result list">
            <?php
                $ads_count = trim($this->listing_number);
                $nb_zero = 6 - strlen($ads_count);
                $all_listing_count = trim($this->all_listing_count);
                $biz_listing_count = trim($this->biz_listing_count);
                $per_listing_count = trim($this->per_listing_count);

                $count = '';
                for ($i=1; $i<=$nb_zero; $i++) {
                    $count = $count.'0';
                }

                $url1 = $_SERVER["REQUEST_URI"];
                if (!empty($_GET['ad_type'])){
                    $url1 = str_replace('&ad_type=personal', '', $url1);
                    $url1 = str_replace('&ad_type=business', '', $url1);
                    $url1 = str_replace('&ad_type=', '', $url1);
                } else {
                    $url1 = $_SERVER["REQUEST_URI"];
                }
            ?>


           <section class="business_personal">  
                <a <?php echo empty($_GET['ad_type']) ? 'class="selected"' : ''?>  href="<?php echo $url1.(strpos($url1, '?')!==false ? '&': '?')?>">
                    <em>所有广告</em>
                    (<?php echo $all_listing_count;?>)
                </a>
                <a <?php echo !empty($_GET['ad_type']) && $_GET['ad_type'] == 'business' ? 'class="selected"' : ''?> href="<?php echo $url1.(strpos($url1, '?')!==false ? '&': '?')?>ad_type=business"><em>商业买卖</em> (<?php echo $biz_listing_count;?>)</a>
                <a <?php echo !empty($_GET['ad_type']) && $_GET['ad_type'] == 'personal' ? 'class="selected"' : ''?> href="<?php echo $url1.(strpos($url1, '?')!==false ? '&': '?')?>ad_type=personal"><em>个人交易</em> (<?php echo $per_listing_count?>)</a>
            </section>

            <ul id="list">
                <?php
                    $display_photo = true;
                    $display_user  = true;
                    $replace_like_with_follow = false;
                    $display_price = true;
                    $display_customization = true;
                    if (!empty($_GET['small_category_list'])) {
                        $cat = Model_Category::find($_GET['small_category_list']);
                        if ($cat->customization == 'job') {
                            $display_photo = false;
                            $display_user  = false;
                            $class = '';
							$display_customization = false;
                        } elseif ($cat->id == 'mc52') { //business directory
                            $display_photo = false;
                            $display_user  = false;
                            $class = '';
                            $replace_like_with_follow = true;
                            $display_price = false;
                            $display_customization = false;
                        }
                    }
                ?>

                <?php  foreach ($this->list as $listing):?>
                    <?php
                        if ($listing->type_obj == Model_Company::TYPE) {
                            $item = Model_Company::find($listing->id);
                        } else {
                            $item = Model_Listing::find($listing->id);
                        }
                    ?>
                    <?php if(empty($item)){ continue;}?>
                    <li class="item">
                        <?php
                            $this->partial()->setObjectKey('model');
                            echo $this->partial(
                                'index/listing-element.phtml',
                                'search',
                                array(
                                    'item'                        => $item,
                                    'photo_width'                 => 120,
                                    'photo_height'                => 120,
                                    'photo_method'                => 'resizeAndCrop',
                                    'photo_params'                => array(),
                                    'display_photo'               => $display_photo,
                                    'display_user'                => $display_user,
                                    'display_photo_if_not_exists' => true,
                                    'display_category'            => true,
                                    'display_customization'       => $display_customization,
                                    'display_date'                => false,
                                    'display_price'               => $display_price,
                                    'replace_like_with_follow'    => $replace_like_with_follow,
                            ));
                        ?>
                    </li>
                <?php endforeach; ?>

                <?php /*foreach($this->list as $listing):?>
                    <?php $item = Model_Listing::find($listing->id);?>
                    <?php if(empty($item)) {continue;}?>
                    <li class="item"> 
                        <?php
                            $this->partial()->setObjectKey('model');
                            echo $this->partial(
                                'index/listing-element.phtml',
                                'search',
                                array(
                                    'item'                  => $item,
                                    'display_customization' => true,
                                    'display_user'          => true,
                                    'lazy_loading'          => false,
                            ));
                        ?>
                    </li>
                <?php endforeach;*/?>
            </ul>
            <?php
                $get = $_GET;
                if (!empty($this->category) && $req['module'] !== 'search') {
                    $url = '';
                    foreach($get as $k => $v) {
                        if (is_array($v)) {
                            foreach($v as $k2 => $v2) {
                                $url .= $k.'['.$k2.']'.'='.$v2.'&';
                            }
                        } else {
                            $url .= $k.'='.$v.'&';
                        }
                    }
    
                    $url = $this->category->url().'?'. $url;
                } else {
                    $url = $this->geturl('regular', 'search', null, array(), $get);
                }
            ?>                                    

            <?php $url1 = preg_replace('#&page=[^&]*#', '', $url);?>
            <?php $pagination = $this->pagination($this->listing_number, $this->page, $this->per_page, 4, $url1);?>
            <?php $separator = (strpos($url, '?') !== false) ? '&' : '?'; ?>
            <section class="nav option top">
                <dl class="sort">
                    <dt>排列</dt>
                    <dd>
                        <?php foreach($this->sort_by as $k => $value):?>
                            <?php $url1 = preg_replace('#&sort=[^&]*#', '', $url);?>
                            <a href="<?php echo $url1.$separator.'sort='.$k?>" class="<?php echo $this->sort == $k ? 'selected': ''?>"><?php echo $value;?></a>
                        <?php endforeach;?>
                    </dd>
                </dl>
                <dl class="view">
                    <dt>显示</dt>
                    <dd>
                        <a href="<?php echo preg_replace('#&view=[^&]*#', '', $url) . $separator . 'view=gallery'?>">相集</a>
                        <a class="selected" href="#">列表</a>
                    </dd>
                </dl>
                <?php echo $pagination;?>
            </section> 
             <section class="nav option bottom">
                <dl class="sort">
                    <dt>排列</dt>
                     <dd>
                        <?php foreach($this->sort_by as $k => $value):?>
                            <?php $url1 = preg_replace('#&sort=[^&]*#', '', $url);?>
                            <a href="<?php echo $url1.$separator.'sort='.$k?>" class="<?php echo $this->sort == $k ? 'selected': ''?>"><?php echo $value;?></a>
                        <?php endforeach;?>
                    </dd>
                </dl>
                <dl class="view">
                    <dt>显示</dt>
                    <dd>
                        <a href="<?php echo preg_replace('#&view=[^&]*#', '', $url) . $separator . 'view=gallery'?>">相集</a>
                        <a class="selected" href="#">列表</a>
                    </dd>
                </dl>
                <?php echo $pagination;?>
            </section> 
       </section>
    </section>
    <aside>
        <?php
            $history  = Model_History::getList();
            $bookmark = Model_Bookmark::getList();
            if (($bookmark === false  || $bookmark->count() == 0) && ($history === false || $history->count() == 0)) {
                return;
            }
            $hide_saved_ads = false;
        ?>

        <section class="history_saved">
            <p class="idTabs">
                <a class="selected" href="#idTab1"  <?php echo $history->count() == 0 ? 'style="display:none"' : ''?> >最近浏览</a>
                <a href="#idTab2" <?php echo $bookmark->count() == 0 ? 'style="display:none"' : ''?> >收藏的宝贝</a>   
            </p>
            <?php if ($history !== false):?>
                <section style="display: block;" id="idTab1" class="history">
                    <ul>
                    <?php $count = 0;?>
                    <?php foreach($history->limit(6) as $hist):?>
                        <?php $item = $hist->listing?>
                        <?php if (empty($item)) {continue;}?>
                        <?php if($item->status != Model_Listing::STATUS_PUBLISHED) {continue;}?>
                        <?php $count++?>
                        <li>
                        <?php
                            $this->partial()->setObjectKey('model');
                            echo $this->partial(
                                'index/listing-element.phtml',
                                'search',
                                array(
                                    'item'                  => $item,
                                    'display_customization' => false,
                                    'display_user'          => false,
                                    'photo_width'           => 60,
                                    'photo_height'          => 60,
                                    'display_category'      => false,
                                    'display_date'          => false
                            ));
                        ?>
                        </li>
                    <?php endforeach;?>
                    </ul>
                    <p><a href="#">查看所有</a></p>
                </section>
            <?php endif;?>
            <?php if ($bookmark !== false):?>
            <section style="display:none" id="idTab2" class="saved">
                <ul>
                    <?php $count = 0;?>
                    <?php foreach($bookmark->limit(6) as $hist):?>
                        <?php $item = $hist->listing?>
                        <?php if (empty($item)) {continue;}?>
                        <?php if($item->status != Model_Listing::STATUS_PUBLISHED) {continue;}?>
                        <?php $count++?>
                    <li>
                        <?php
                            $this->partial()->setObjectKey('model');
                            echo $this->partial(
                                'index/listing-element.phtml',
                                'search',
                                array(
                                    'item'                  => $item,
                                    'display_customization' => false,
                                    'display_user'          => false,
                                    'photo_width'           => 60,
                                    'photo_height'          => 60,
                                    'display_category'      => false,
                                    'display_date'          => false
                            ));
                        ?>            
                    </li>
                    <?php endforeach;?>
                </ul>
                <p><a href="#">观看所有</a></p>
            </section>
            <?php endif;?>
        </section>
    </aside>
    
</article>
